package smedi.ismedi.mobile.bff.controller.authortiy;

import com.smedi.ismedi.authoritymanagement.api.dto.request.*;
import com.smedi.ismedi.authoritymanagement.api.dto.response.ElementNodeResponse;
import com.smedi.ismedi.authoritymanagement.api.dto.response.ElementResponse;
import com.smedi.ismedi.authoritymanagement.api.feign.RemoteElementFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: xulinjun
 * @Date: 2021-7-2 10:51
 */
@Slf4j
@RestController
@Api(tags = {"元素"})
@RequestMapping("/mobilebff/v1")
@AllArgsConstructor
public class ElementController implements RemoteElementFeignApi {
    private final RemoteElementFeignApi remoteElementFeignApi;

    /**
     * 新增 元素
     *
     * @param elementCreateRequest 元素 新增 请求
     * @return public ResponseData<ElementResponse>
     */
    @ApiOperation(httpMethod = "POST", value = "新增 元素")
    @PostMapping(value = "/element/create")
    public ResponseData<ElementResponse> createElement(@Validated @RequestBody ElementCreateRequest elementCreateRequest) {
        return remoteElementFeignApi.createElement(elementCreateRequest);
    }


    /**
     * 编辑 元素
     *
     * @param elementEditRequest 元素 编辑 请求
     * @return public ResponseData<ElementResponse>
     */
    @ApiOperation(httpMethod = "POST", value = "编辑 元素")
    @PostMapping(value = "/element/edit")
    public ResponseData<ElementResponse> editElement(@Validated @RequestBody ElementEditRequest elementEditRequest) {
        return remoteElementFeignApi.editElement(elementEditRequest);
    }


    /**
     * 批量 编辑 元素
     *
     * @param elementEditRequests 元素 编辑 请求
     * @return public ResponseData<ElementResponse>
     */
    @ApiOperation(httpMethod = "POST", value = "批量 编辑 元素")
    @PostMapping(value = "/element/edit/batch")
    public ResponseData<Boolean> editElements(@Validated @RequestBody List<ElementEditRequest> elementEditRequests) {
        return remoteElementFeignApi.editElements(elementEditRequests);
    }


    /**
     * 删除 元素
     *
     * @param elementRemoveRequest 元素 删除 请求
     * @return public ResponseData<ElementResponse>
     */
    @ApiOperation(httpMethod = "POST", value = "删除 元素")
    @PostMapping(value = "/element/remove")
    public ResponseData<Boolean> removeElement(@Validated @RequestBody ElementRemoveRequest elementRemoveRequest) {
        return remoteElementFeignApi.removeElement(elementRemoveRequest);
    }


    /**
     * 获取 元素 单一
     *
     * @param elementOneRequest 元素 单一 请求
     * @return public ResponseData<ElementResponse>
     */
    @ApiOperation(value = "获取 元素 单一", nickname = "获取 元素 单一")
    @PostMapping(value = "/element/one")
    public ResponseData<ElementResponse> getElementOne(@Validated @RequestBody ElementOneRequest elementOneRequest) {
        return remoteElementFeignApi.getElementOne(elementOneRequest);
    }

    /**
     * 获取 元素 列表
     *
     * @param elementListRequest 元素 列表 请求
     * @return public ResponseData<List < ElementResponse>>
     */
    @ApiOperation(value = "获取 元素 列表", nickname = "获取 元素 列表")
    @PostMapping(value = "/element/list")
    public ResponseData<List<ElementResponse>> getElementList(@Validated @RequestBody ElementListRequest elementListRequest) {
        return remoteElementFeignApi.getElementList(elementListRequest);
    }

    /**
     * 获取 元素 分页
     *
     * @param elementPageRequest 元素 分页 请求
     * @return public ResponseData<PaginationData < ElementResponse>>
     */
    @ApiOperation(value = "获取 元素 分页", nickname = "获取 元素 分页")
    @PostMapping(value = "/element/page")
    public ResponseData<PaginationData<ElementResponse>> getElementPage(@Validated @RequestBody ElementPageRequest elementPageRequest) {
        return remoteElementFeignApi.getElementPage(elementPageRequest);
    }

    /**
     * 获取 元素 树
     *
     * @return public ResponseData<List < TermPageResponse>>
     */
    @ApiOperation(httpMethod = "POST", value = "获取 元素 树")
    @PostMapping(value = "/element/tree")
    public ResponseData<List<ElementNodeResponse>> getTree(@Validated @RequestBody ElementTreeRequest elementPageRequest) {
        return remoteElementFeignApi.getTree(elementPageRequest);
    }

    /**
     * 保存 角色与元素关系
     *
     * @return public ResponseData<Boolean>
     */
    @ApiOperation(httpMethod = "POST", value = "保存 角色与元素关系")
    @PostMapping(value = "/role-element-relationship/save")
    public ResponseData<Boolean> saveRoleElementRelationship(@Validated @RequestBody RoleElementRelationshipSaveRequest roleElementRelationshipSaveRequest) {
        return remoteElementFeignApi.saveRoleElementRelationship(roleElementRelationshipSaveRequest);
    }
}
